<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/layouts/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>文件系统</title>
	<%@include file="/WEB-INF/layouts/index-header.jsp"%>
</head>
<body>

<div class="tpanel">
	<div class="panel-content">
		<div class="container-fluid">
			<div id="tool">
				<form id="searchForm" class="form-inline" onsubmit="return query()" style="margin-top:20px;margin-bottom:20px;">
					<div class="form-group">
						<label class="">文件夹路径：</label>
						<input type="text" id="folderPath" name="folderPath" class="form-control"/>
					</div>
					<div class="form-group">
						<button type="submit" class="btn btn-primary radius">
							<span class="glyphicon glyphicon-search"></span> 查询
						</button>
						<button type="button" class="btn btn-primary radius" onclick="tomcatLogs()">
							<span class="glyphicon glyphicon-search"></span> Tomcat日志
						</button>
						<button type="button" class="btn btn-primary radius" onclick="parentDir()">
							<span class="glyphicon glyphicon-search"></span> 上级目录
						</button>
					</div>
				</form>
			</div>
			<p>当前目录：<span id="curDir"></span></p>
			<table id="table"></table>
		</div>
	</div>
</div>

<script type="text/javascript">
    changeTitle('文件系统');

    $(function() {
        $('#table').bootstrapTable({
            url: '${ctx}/admin/file-system/list',
            striped : true,
            mobileResponsive : true,
            checkOnInit : true,
            idField : 'id',
            uniqueId : 'id',
            checkbox : true,
            clickToSelect : true,
            queryParams : function(params, searchForm) {
                $('#curDir').text('');
                if(!searchForm) {
                    searchForm = '#searchForm';
                }
                var form = $(searchForm).serializeObject();
                for(var i in form) {
                    params[i] = form[i];
                }
                return params;
            },
            responseHandler : function(res) {
                if(res.code != 'OK') {
                    if(res.message.indexOf('[]') == -1) {
                        topLayer.msg(res.message, {icon: 2});
					}
                    return new Array();
				}
                $('#folderPath').val(res.body.folderPath.replace(/\\/g,"/"));
                $('#curDir').text(res.body.folderPath.replace(/\\/g,"/"));
                if(res.body && res.body.list) {
                    return res.body.list;
				}else {
                 	return new Array();
				}
            },
            columns: [/*{
                field: 'ck',
                checkbox : true
            },*/{
                title: '#',
                width : 50,
                align : 'center',
                formatter: snFormatter
            },{
                field: 'name',
                title: '文件名',
                align : 'left',
				formatter : function(value,row,index) {
					if(row.directory) {
					    return '<a style="color:#51b4b9" href="javascript:query(\'' + row.path.replace(/\\/g,"/") + '\')">' +
							'<span class="iconfont icon-lunboyoufangun"></span> '
							+ value + '</a>';
					}
					return '<a style="color:#00adff" target="_blank"' +
						'href="${ctx}/admin/file-system/get?filePath=' + row.path.replace(/\\/g,"/") + '">' +
						'<span class="iconfont icon-caidanguanli"></span> '
						+ value + '</a>';
				}
            },{
                field: 'size',
                title: '文件大小',
                align : 'center',
                formatter : function(value,row,index) {
                    return (value * 1.0 / 1024).toFixed(2) + 'K';
                }
            },{
                field: 'lastModified',
                title: '最后修改时间',
                'class' : 'nowrap',
                align : 'center'
            }]
        });

    });

    function parentDir() {
        $('#table').bootstrapTable('refreshOptions',{url: '${ctx}/admin/file-system/parent'});
        return search('#searchForm','#table');
    }

    function query(folderPath) {
        if(folderPath && folderPath.length > 0) {
            $('#folderPath').val(folderPath);
		}
        $('#table').bootstrapTable('refreshOptions',{url: '${ctx}/admin/file-system/list'});
        return search('#searchForm','#table');
	}

    function tomcatLogs() {
        $('#table').bootstrapTable('refreshOptions',{url: '${ctx}/admin/file-system/tomcat-logs'});
	}

    function del(id) {
        carefulDelete('${ctx}/admin/sys-user/careful-delete',id,'请输入您的管理密码以确定删除此系统用户');
    }

</script>

</body>
</html>